import cn.bdqn.entity.Customer;
import cn.bdqn.mapper.CustomerMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @Description TODO
 * @Date 2020/2/5 15:55
 * @Created by 张三三
 */
public class CustomerTest2 {
    private SqlSession session = null;

    @Before
    public void before() throws IOException {
        InputStream is = Resources.getResourceAsStream("configuration.xml");
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
        session = factory.openSession(true);
    }
    @After
    public void after(){
        session.close();
    }

    @Test
    public void selectAll(){
        CustomerMapper mapper = session.getMapper(CustomerMapper.class);
        List<Customer> customers = mapper.selectAll();
        for (Customer customer : customers) {
            System.out.println("customer = " + customer);
        }
    }




}
